package com.pai4j.common.service.messagequeue.producer;

import jakarta.annotation.Resource;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Service;
/**
 * RocketMQ消息队列发送者
 *
 * @author: CYM-pai
 * @date: 2025/04/29 21:14
 **/
@Service
public class RocketMessageQueueSender<T, P> extends AbstractMessageQueueSender<T, P> {

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    @Override
    protected boolean doSend(String queue, T message) {
        // 同步消息发送
        SendResult result = rocketMQTemplate.syncSend(queue, super.serializeMessage(message));
        return SendStatus.SEND_OK.equals(result.getSendStatus());
    }

    @Override
    protected boolean broadSend(String channel, T message) {
        // 对RocketMQ而言，广播模式的关键在于消费者端的配置。消费者需要明确指定消费模式为广播模式
        return this.doSend(channel, message);
    }

    @Override
    protected boolean prioritySend(String channel, T message, P priority) {
        return false;
    }
}
